<template>
	<view>
		<view v-if="loaded || list.itemIndex < 15" class="uni-indexed-list__title-wrapper">
			<text v-if="list.items && list.items.length > 0" class="uni-indexed-list__title">{{ list.key }}</text>
		</view>
		<view v-if="(loaded || list.itemIndex < 15) && list.items && list.items.length > 0"
			class="uni-indexed-list__list">
			<view v-for="(item, index) in list.items" :key="index" class="uni-indexed-list__item"
				hover-class="uni-indexed-list__item--hover">
				<view class="sol-indexed-list__item-container" @click="onClick(idx, index)">
					<sol-avatar class="sol-indexed-list__item-left" src="https://dummyimage.com/200x200" :gender="1" size="md"></sol-avatar>
					<view class="sol-indexed-list__item-right"
						:class="{'sol-indexed-list__item-right_last':index===list.items.length-1}">
						<text class="sol-indexed-list__item-right_name" v-text="item.name">昵称</text>
						<text class="sol-indexed-list__item-right_text">时间</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'UniIndexedList',
		emits: ['itemClick'],
		props: {
			loaded: {
				type: Boolean,
				default: false
			},
			idx: {
				type: Number,
				default: 0
			},
			list: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		methods: {
			onClick(idx, index) {
				this.$emit("itemClick", {
					idx,
					index
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-indexed-list__list {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		margin: 28rpx;
		padding: 28rpx;
		border-radius: 28rpx;
		background-color: #474e54;
	}

	.uni-indexed-list__item {
		font-size: 28rpx;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex: 1;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.uni-indexed-list {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	.uni-indexed-list__title-wrapper {
		/* #ifndef APP-NVUE */
		display: flex;
		width: 100%;
		/* #endif */
		background-color: transparen;
	}

	.uni-indexed-list__title {
		padding: 18rpx 28rpx;
		line-height: 44rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #DDDDDD;
	}

	.sol-indexed-list__item {
		&-container {
			flex: 1;
			position: relative;
			/* #ifndef APP-NVUE */
			display: flex;
			box-sizing: border-box;
			/* #endif */
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			/* #ifdef H5 */
			cursor: pointer;
			/* #endif */
		}

		&-left {
			margin-right: 28rpx;
		}

		&-right {
			flex: 1;
			position: relative;
			display: flex;
			box-sizing: border-box;
			flex-direction: column;
			justify-content: space-between;
			align-items: flex-start;
			height: 144rpx;
			padding: 28rpx 18rpx;
			border-bottom: 2rpx solid #576069;

			&_last {
				border-bottom: none;
				margin-bottom: 0;
				padding-bottom: 0;
			}

			&_name {
				font-size: 32rpx;
				font-weight: 400;
				color: #BBBBBB;
			}

			&_text {
				font-size: 28rpx;
				font-weight: 400;
				color: #DDDDDD;
				padding-top: 18rpx;
			}
		}
	}
</style>
